package cn.yunhe.service;

import cn.yunhe.dao.OrderDetailDao;
import cn.yunhe.entity.OrderDetail;
import cn.yunhe.entity.Product;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderDetailService {
    SqlSession session = SqlSessionFactoryUtil.getSession();
    OrderDetailDao orderDetailDao = session.getMapper(OrderDetailDao.class);

    //得到用户购物车信息
    public List<OrderDetail> getUserShopping(int userid){
        List<OrderDetail> orderDetailList=orderDetailDao.getUserShopping(userid);
        session.close();
        return orderDetailList;
    }
    //批量删除购物车中订单
    public boolean delShopping(List list){
        boolean flag=orderDetailDao.delShopping(list);
        session.commit();
        session.close();
        return flag;
    }
    //修改购物车订单商品数量
    public boolean updQuantity(int quantity,int eodid){
        Map<String ,Integer> map=new HashMap<String ,Integer>();
        map.put("quantity",quantity);
        map.put("eodid",eodid);

        boolean flag=orderDetailDao.updQuantity(map);
        session.commit();
        session.close();
        return flag;
    }
    //增加购物车订单
    public boolean addShopping(OrderDetail orderDetail){
        boolean flag=orderDetailDao.addShopping(orderDetail);
        session.commit();
        session.close();
        return flag;
    }
    //增加订单时检查购物车是否已有该商品订单
    public boolean searchProductOrderOfUser(OrderDetail orderDetail){
        int a=orderDetailDao.searchProductOrderOfUser(orderDetail);
        boolean flag=true;
        if(a!=0){
            flag=false;
        }
        return flag;
    }
}
